/**
Router for express
*/

/**
* Module depandence
*/
var error = require('./errorpage');
//var controllerapi = require('./controllers/api');
var controllerui = require('./controllers/ui');
var controllererror = require('./controllers/error');

var debug = true;
/**
* Module exports.
*/
module.exports = Router;

//Construction
function Router(app){
  this.version = '0.1.0';
  console.log("Router construction.");
  this._app = app;
  this.route = function(action,routePath){
     routePath = routePath || '';
     for(var key in action){
        switch( typeof action[key]){
          case 'object':
            route(action[key],routePath + key);
            break;
          case 'function':
            if(debug) console.log('%s - %s', key,routePath);
            _app[key](routePath,action[key]);
           break;
        }
     }
  };
  this.initRouter = function(){
      if(debug) console.log("Init Router.");
      //
      controllerapi.initRoute(this);
      //
      controllerui.initRoute(this);
      //
      if(!debug)
        controllererror.initRoute(this);
  };
  // register error process
  error.errorpage(this);
  return this;
} 

